from functools import wraps
from flask_jwt_extended import get_jwt_identity
from app.models import BlogUser, CommonResult


def is_staff_user(func):
    """后台用户装饰器
    """

    @wraps(func)
    def inner(*args, **kwargs):
        user_id = get_jwt_identity()
        user = BlogUser.query.get(user_id)
        if user and user.staff_user:
            ret = func(*args, **kwargs)
        else:
            return CommonResult(code=403, msg="不是后台管理用户")
        return ret

    return inner
